/**
 * 
 */
package com.iwords.service.persistence.impl;

import java.util.List;

import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

import com.iwords.service.object.FeedbackEntity;
import com.iwords.service.persistence.FeedbackPersistence;

/**
 * @author qianxiang
 *
 */
@Stateless
public class FeedbackPersistenceImpl implements FeedbackPersistence {
	@PersistenceContext(unitName = "iwords")
	private EntityManager em;
	
	protected EntityManager getEntityManager() {
		return em;
	}
	
	@SuppressWarnings("unchecked")
	@Override
	public List<FeedbackEntity> findLatestFeedbacks() {
		String jpql = "select o from FeedbackEntity o order by o.createtime desc";
		Query query = getEntityManager().createQuery(jpql);
		query.setFirstResult(0);
		query.setMaxResults(10);
		
		return query.getResultList();
	}
	
	@Override
	public void create(FeedbackEntity entity) {
		getEntityManager().persist(entity);
	}
	
}
